package com.shenrongrong.config;

import com.shenrongrong.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyConfig implements WebMvcConfigurer {//web配置
    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {//拦截器配置
        registry.addInterceptor(jwtInterceptor) //<bean class = "com.xxx.interceptor.xx/> 注册拦截器
                .addPathPatterns("/**")//被拦截的
                .excludePathPatterns("/loginUser","/insertUser","/upload","/images/**");//不被拦截的
    }
    //本地盘符静态资源映射  /images/** => D:/images/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**")
                .addResourceLocations("file:D:/images/");
    }
}
